package com.tedu.day01.oop;


import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class ColorJPanel extends JPanel implements Runnable{
	int time=0;
	 Thread t;
	public ColorJPanel(){
		setBackground(Color.BLACK);
		t=new Thread(this);
		t.start();
		
	}
	
	public void run() {	
		while(true){			
			time++;			
			if(time==10){
				setBackground(Color.YELLOW);
			}
			if(time==20){
				setBackground(Color.RED);
			}if(time==30){
				setBackground(Color.BLACK);
			}if(time==40){
				time=0;
			}
			repaint();
		    try {
				Thread.sleep(100);
			} catch (InterruptedException e) {				
				e.printStackTrace();
			}
		}
	}
}